package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.*;
import cn.gson.springboot.model.pjos.Process;
import cn.gson.springboot.model.service.afterservice.MaintainService;
import cn.gson.springboot.model.vo.aftervo.*;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/crm")
public class MaintainController {

    @Autowired
    MaintainService sc;

    @RequestMapping("/main-page")
    @ResponseBody
    public Map<String, Object> mainPage(Integer stateId, String search, Integer currPage, Integer pageSize) {
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Maintain> main = sc.selectPage(stateId, search);

        Map<String, Object> map = new HashMap<>();
        map.put("rows", obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total", obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("/order-name")
    @ResponseBody
    public String orderName() {
        return sc.selectMaxBusinessName();
    }

    @RequestMapping("/save-tain")
    @ResponseBody
    public void saveTain(@RequestBody MaintainVo tain) {
        System.out.println(tain.toString());
        sc.addTain(tain);
    }

    @RequestMapping("/save-pros")
    @ResponseBody
    public void savePros(@RequestBody ProcessVo pros) {
        sc.addPros(pros);
    }

    @RequestMapping("/check-all")
    @ResponseBody
    public List<Customer> checkAll() {
        return sc.customerAll();
    }

    @RequestMapping("/check-dept")
    @ResponseBody
    public List<Dept> checkDept() {
        return sc.selectDept();
    }

    @RequestMapping("/check-link")
    @ResponseBody
    public List<Culinkman> checkLink(Integer person) {
        return sc.selectLink(person);
    }

    @RequestMapping("/check-tain")
    @ResponseBody
    public Maintain checkTain(Integer tainIds) {
        return sc.selectTain(tainIds);
    }

    @RequestMapping("/check-main")
    @ResponseBody
    public MaintainDetail checkMain(Integer tainIds) {
        return sc.selectMain(tainIds);
    }

    @RequestMapping("/check-schedu")
    @ResponseBody
    public List<Schedule> checkSchedu() {
        return sc.selectSchedu();
    }

    @RequestMapping("/update-state")
    @ResponseBody
    public void updateState(Integer tainId) {
        sc.changeTains(tainId);
    }

    @RequestMapping("/update-two")
    @ResponseBody
    public void updateTwo(Integer tainId) {
        sc.changeTwo(tainId);
    }

    @RequestMapping("/update-three")
    @ResponseBody
    public void updateThree(Integer tainId) {
        sc.changeThree(tainId);
    }

    @RequestMapping("/update-no")
    @ResponseBody
    public void updateNo(Integer tainId) {
        sc.changeNo(tainId);
    }

    @RequestMapping("/update-four")
    @ResponseBody
    public void updateFour(Integer tainId) {
        sc.changeFour(tainId);
    }

    @RequestMapping("/update-five")
    @ResponseBody
    public void updateFive(Integer tainId) {
        sc.changeFive(tainId);
    }

    @RequestMapping("/update-six")
    @ResponseBody
    public void updateSix(Integer tainId) {
        sc.changeSix(tainId);
    }

    @RequestMapping("/check-pros")
    @ResponseBody
    public Process checkPros(Integer tainIds) {
        return sc.selectPros(tainIds);
    }

    @RequestMapping("/check-flow")
    @ResponseBody
    public Interflow checkFlow(Integer tainIds) {
        return sc.selectFlow(tainIds);
    }

    @RequestMapping("/check-cour")
    @ResponseBody
    public Course checkCour(Integer tainIds) {
        return sc.selectCour(tainIds);
    }

    @RequestMapping("/save-info")
    @ResponseBody
    public void saveInfo(@RequestBody Interflow info) {
        sc.addInfo(info);
    }

    @RequestMapping("/save-cour")
    @ResponseBody
    public void saveCour(@RequestBody Course cour) {
        sc.addCour(cour);
    }

    @RequestMapping("/check-state")
    @ResponseBody
    public Integer checkState(Integer tainIds) {
        return sc.checkStateId(tainIds);
    }

    @RequestMapping("/delete-tain")
    @ResponseBody
    public void deleteTain(Integer tainId) {
        sc.deleteByTainId(tainId);
    }

    @RequestMapping("/repair-month")
    @ResponseBody
    public List<MaintainChartVo> repairMonth() {
        return sc.selectRepairByMonth();
    }

    @RequestMapping("/money-month")
    @ResponseBody
    public List<PieDoubleVo> moneyMonth() {
        return sc.selectMoneyByMonth();
    }

    @RequestMapping("/delivered-id")
    @ResponseBody
    public List<Integer> deliveredId() {
        return sc.selectDeliveredById();
    }

    @RequestMapping("/delivered-month")
    @ResponseBody
    public List<String> deliveredMonth() {
        return sc.selectDeliveredByMonth();
    }

    @RequestMapping("/undelivered-state")
    @ResponseBody
    public List<Integer> undeliveredState() {
        return sc.selectUndeliveredByState();
    }

    @RequestMapping("/undelivered-month")
    @ResponseBody
    public List<String> undeliveredMonth() {
        return sc.selectUndeliveredByMonth();
    }

    @RequestMapping("/order-count")
    @ResponseBody
    public List<Integer> orderCount() {
        return sc.selectOrderByCount();
    }

    @RequestMapping("/order-month")
    @ResponseBody
    public List<String> orderMonth() {
        return sc.selectOrderByMonth();
    }

    @RequestMapping("/funnel-state")
    @ResponseBody
    public List<MaintainChartVo> funnelState() {
        return sc.selectFunnelByState();
    }

    @RequestMapping("/tain-two")
    @ResponseBody
    public List<Maintain> tainTwo() {
        return sc.selectTainByTwo();
    }

    @RequestMapping("/tain-three")
    @ResponseBody
    public List<Maintain> tainThree() {
        return sc.selectTainByThree();
    }

    @RequestMapping("/tain-four")
    @ResponseBody
    public List<Maintain> tainFour() {
        return sc.selectTainByFour();
    }

    @RequestMapping("/tain-five")
    @ResponseBody
    public List<Maintain> tainFive() {
        return sc.selectTainByFive();
    }

    @RequestMapping("/tain-six")
    @ResponseBody
    public List<Maintain> tainSix() {
        return sc.selectTainBySix();
    }

    @RequestMapping("/tain-seven")
    @ResponseBody
    public List<Maintain> tainSeven() {
        return sc.selectTainBySeven();
    }

    @RequestMapping("/tain-eight")
    @ResponseBody
    public List<Maintain> tainEight() {
        return sc.selectTainByEight();
    }

    @RequestMapping("/order-tainid")
    @ResponseBody
    public Integer OrderTainId(String tainOrder) {
        return sc.selectOrderByTainId(tainOrder);
    }

    @RequestMapping("/check-type")
    @ResponseBody
    public List<Map<String, Object>> checkType(String tainType) {
        List<Map<String, Object>> list = sc.selectByType(tainType);
        return list;
    }

    @RequestMapping("/product-id")
    @ResponseBody
    public List<MainProductVo> productId(String tainType, String tainNote) {
        return sc.selectProductId(tainType, tainNote);
    }

    @RequestMapping("/customer-id")
    @ResponseBody
    public List<Customer> customerId(String tainType, String tainNote) {
        return sc.customerById(tainType, tainNote);
    }

    @RequestMapping("/repair-emp")
    @ResponseBody
    public List<Emp> repairEmp(){
        return sc.selectRepairEmp();
    }
}
